<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8"/>
    <title>organization maintain</title>
    <link rel="stylesheet" th:href="@{/css/css.css}">
</head>
<body>

<form id="form" method="post" action="">
    <input type="hidden" name="id" th:value="${organization.id}">
    <input type="hidden" name="parentId" th:value="${organization.parentId}">
    <input type="hidden" name="parentIds" th:value="${organization.parentIds}">
    <input type="hidden" name="available" th:value="${organization.available}">

    <div class="form-group">
        <table>
            <tr>
                <th colspan="2"><label>名称</label></th>
                <td colspan="2"><input type="text" name="name" th:value="${organization.name}"></td>
            </tr>

            <tr>
                <shiro:hasPermission name="organization:update">
                    <td><input type="button" id="updateBtn" value="修改"></td>
                </shiro:hasPermission>

                <shiro:hasPermission name="organization:delete">
                    <td><input type="button" id="deleteBtn" value="删除"></td>
                </shiro:hasPermission>
                <shiro:hasPermission name="organization:create">
                    <td><input type="button" id="appendChildBtn" value="添加子节点"></td>
                </shiro:hasPermission>
                <shiro:hasPermission name="organization:update">
                    <td><input type="button" id="moveBtn" value="移动节点"></td>
                </shiro:hasPermission>
            </tr>
        </table>
    </div>

</form>
<script th:src="@{/js/jquery-1.11.0.min.js}"></script>
<script th:inline="javascript">
    var organizationId = [[${organization.id}]];
    $(function () {
        $("#updateBtn").click(function () {
            $("#form")
                    .attr("action", "/organization/" + organizationId + "/update")
                    .submit();
            return false;
        });
        $("#deleteBtn").click(function () {
            if (confirm("确认删除吗？")) {
                $("#form")
                        .attr("action", "/organization/" + organizationId + "/delete")
                        .submit();
            }
            return false;
        });

        $("#appendChildBtn").click(function () {
            location.href = "/organization/" + organizationId + "/appendChild";
            return false;
        });

        $("#moveBtn").click(function () {
            location.href = "/organization/" + organizationId + "/move";
            return false;
        });
    });
</script>
</body>
</html>